restructure lib a bit. added initial code for the new rules stuff
make things more typesafe