modernized and cleaned up a bit