Changed if condition to -z operator (works properly now)