optimize implementation