Function optimization
Code clean up