Added function comment and refectored