refactored #57 a bit