Speed optimization and various bug fixes.