Handle POST request, and some refactors