further fixing and cleanup