Horrible preliminary version is done, have to refactor though