Cleaned up code to compile with -Wall. Debugged.