fix #38 amend + refactor