Restructure and add some documentation