Fixed many corner cases