bugfixes, code standardization, refactoring

See notes on commit for details