Separate into reusable files and test