Refactoring out some complex methods.
Added getXSize and getYSize methods.