Improved efficiency and many bug fixes