Fixed various run-time issues and variable assignment inconsistencies. Pending experimental design changes, code is ready to run.