code cleanup and ajax polling