improve efficiency as suggested by @ali-graham