Adding some core and UI spec tests and refactoring some core code to fix the new tests that failed.