Added includes for printf and solved minor bugs.