organize globals
make all functions stateless