Cleaned up code, fixed warnings