Added automatic tile size detection and fixed small out of range error.