Added size checking, and fixed file object selection.