Code restructuring - fixes #10