Added POST code and refactoring, not tested yet