Code reduction and tidy up