modified as per jainams comments