Improved documentation/comments and added sanity checks where speed is used