Fixed the error in teh inputs, cleaned up code