refactored POST logic into a single method inside server loop