Working problem #50. Needs optimization