simplifying the code a bit for bugfixing. still a work in progress