minor changes; cleaned up code and modularization