cleaned up code and fixed a few things