Correct all warnings and errors during compilation + various bug fixes