Bug fix

Some bug fixen, started working on the preferences system