ugly but almost done