working version, small adjustments