started cleaning code a bit. It is a mess.