working version

Todo: Error checking and handling