Added POST and PUT functionality, and refactored code.