Fix some return types and incorrect use of length
Add first functions for possible profiling/timing