fixed some bugs, to do: add frontend functions