Code optimized and re-formatted.