moved common functions into separate files