solved next page problem, moved function position fixing a haunting bug