Refactor code and clear form inputs after post