Changed method of detecting an input type
Made code more readable