more updated code. fixed certian bugs