Complete reconstruction

Edits to most parts of the program.