GH-5 Made style changes & cleaned up code

declared all variables at the top of the scope;
used self instead to access global vars consistently;
replaced .parent with core API's getParent function;
removed unnecessary variables