added comments + simplified a lot (needs to be tested)