Added some comments and profiling.