moved if statement for better errors