Adding tests for the currect functionality and fix some bugs