Done some messy writing -- to be cleaned up later