Fixed minor errors
Cleaned up code