Bug fixes and refactoring

Still so much to do to get foreground UI up and running... it is getting
there slowly but surely!