rebase again, todo: major cleanup, remove comments and delete unused functions