Fixed very strange behavior in some cases