I think this should address #11 - needs some testing