reworked

changed a few things for ease of reading and added a few functions