Removed factories and tidied up code.