Extract shared code from handlers

Javadoc is missing