working well. now to optimize