Removed lots of global variables. Restructured package.