refactored everything to make it easier to understand

cleanup before submit