Refactored some code for bether naming and coments.