simplified and cleaned up