tidied code, renamed some things