add unittest and bugfix