Use :when instead of :pre and a minor refactor