Some debuging and refectoring. Still doesn't work as intended..