Fixe some bugs. Tests needed!