Cleaned up code, reverted some erros