Fixed issue #24 and implemented issue #23