remove useless checking and improve code structure