Horrible first working version. Major refactor needed