helper functions sourced out
helper functions sourced out
restructured the code