Refactoring and small fix

This should fix #306 but I can't confirm this since I can't do the right click.