Speed optimization and fixes