Fixed a bug where y coordinates could become invalid