Spruced up some bugs and added more robustness