Patch 5

Cleaned code and fixt some bugs