Clean up

Remove duplication and simplify code