added preferences and a lot of bug fixes