Applied refactorings as suggested in answers on CodeReview: http://codereview.stackexchange.com/questions/70178