various scope related bugs and things