change optimization from script to method