Refactor to simplify code [afurdell]