refactoring of https://code.google.com/p/javasimon/issues/detail?id=129
(cherry picked from commit 087ab1a)