Better error checking implemented & bugs squashed

TODO clean up use of global Pebble object