Updated to create Cast object, also refactor and tidy up of code