updated code, made it faster