improve performance

I profiled and improved some of the most time consuming functions.