Fixed parseint error in preferences and did some cleanup of the code.