Do not parse integers more times than necessary.
Abstracted code into own function.
Less code duplication.
Abstracted code out into its own function.
Renamed function.
Renamed variable.
Renamed functions.
Added a few comments.