Code tidy up, removed some unused parts