Fixed more bugs which were discovered during testing, final working submission version.