Cleaned up code to compile with -Wall. Still a few bugs