fixes issue #3
fixes issue #2?
neaten code a little
fixes #1