extend function improved