Fixed setup issues, and restructured code