Fixed Bugs, improved speed

Fixed some minor issues and improved b