Improve and trim codes