refactor get and post functions