added all functionality, several bugs left