analysis fully working, optimization still to come