Check type of data, return proper type

Fix issue #1