why so many if and else ,the code is ugly