Refactored solution to comply with java coding conventions