refactored all into one file