moved all relevant code to one file