Another round of fixing and cleanup