updated and reworked code a little bit