Some improvement and bugfix