added #163. needs testing. also worked on #123