Moved if statement inside previous if-block, otherwise it would have sometimes been called unnecessarily