Write Jasmine tests and fix all broken functions