Added simple profiling and some fixes