Pretty good start for issue #8, needs more testing