bug fix. really need more tests!