Fixed realizing function (small bug in IF statement)