code cleaned and definitions moved to new file