cleaning code + some bug fixes