Fix install dependencies, fix bugs and clean up code