Extracted code into methods for easier readability.

Added `m` naming convention to private variables.