remove unused @temp variable
move code to separate files