Implementing serializable and tidying up code