massive bug fixing and polishing