Move searching and serialising into lib classes