Synced with latest version of code modified by Tom Klapiscak