refactor, add call logging, bug fix