Refactored some code as a start.

used var, inverted ifs and moved resources to the resource file.