merged from Yousuf's code
finish the preput method