Reworked code

Reworked a lot of code, deleted not needed, optimized and made it look
better(at least for me). If anyone find any bug please report them.