Tidied code. Included method for sending post request