Moved logic to the correct place