improved as per comments