Code clean up. Arranged function declarations