Some new functions and optimizations added