Cleaned up code and fixed warnings