Made the api more stable and rewritten a part.