try to optimise the code but failed