Third phase and general cleanup

Most changes as suggested in last PR