moved functions to library.R
main.R will only contain logic