Added ErrorLog and refactored most code