Many small modifications - working version