final code working. no more bugs