fix and optimize