Added includes, and fixed some bugs