Finished code

Ready for bugtesting