Removed warnings. Some rewriting.