rafctoring bug fixing