Cleaned, updated version, refactored