Fixing errors, refactoing.