Added support for automatic type detection from an array of values
Made loop more concise and like rest of code