Fix search bar and migrate some user-related functions to /lib