fixing if statements inside a @first / @last block