Some fixes and implementations

Fixed some speed issues, some functions and changed a few things.