Minor changes to code; reorganized too

Cleaned up software and fixed bugs too that would otherwise throw
exceptions