Fixes #57, small code structure changes