tidying and some modification