Add better profiling

also some cleanup