Raw version, poor code quality but working