changed input and output, cleaned up code