refactored submit code