huge refactor, almost an alpha version :)