workingish version
finished for now?