Remove unnecessary nil assignment and improve code base