Finished coding

all functionality works. Will add comment later.