Refactor code and Add submit method