refactor and method additions plus bugs