fixed faulty code