code cleanup and making the preferences screen work