Fixed bug in if structure