refactor previous changes, move to seperate file