rewrite code to avoid NoSuchMethodException. Closes #23