Modifying classpath takes previous attributes into account

This little PR is loosely related to #182. It is not a good practice to create new entries, this change takes previous attributes into account. Also i refactored the code so i think it is a little bit cleaner now. I did not add any tests, since there is nothing to test in this PR.