version 1, functions tested and working