added a sleep function to the main loop to conserve cpu. Pretty primitive but functions perfectly