working, but need alot of improvement and optim
clean up