code optimizing, bug fixes