Optimise function more.
Organized code structure.