fixed bug with duplicate function