Added basic functionality and tidied up some stuff