Add user_exists function, fix some bugs

Unit tests should work again now.