I have found a really basic error in your program, assuming that I am doing my tests correctly. Here is something you can duplicate. Click on the viewing location, then click Other . . ., then click Latitude/Longitude. Set a longitude of 0 (zero degrees). Latitude is not particularly important, but you can set it at 50 degrees North. Then set the time for exactly midnight, July 4, 2011. Stop the time flow rate so that time is not changing. Then look at the declination value for the sun (I get 22d 50m 15s) and for Polaris (I get 89d 18m 52s). The published ephemeris values for this longitude and time are respectively 22d 55m 14.9s and 89d 18m 35s. Please let me know if my data makes any sense to you.
Accuracy of Polaris Declination value