tidied functions and created tests