bug910403: Removed repeat code and added functions. Fixed Styling and Indentation.